package com.store.app.adapter;

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.content.ClipboardManager;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.store.app.R;
import com.store.app.utils.ToastUtils;

public class MessageAdapter extends BaseAdapter{
	private Context context;		//上下文对象引用
	private  List<String> data = new ArrayList<String>();
	private int pos = -1;			//列表位置
	/**
	 * 构造函数
	 * @param context	上下文
	 * @param mp3Infos  集合对象
	 */
	public MessageAdapter(Context context, List<String> data) {
		this.context = context;
		this.data=data;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}


	@Override
	public Object getItem(int position) {
		return position;
	}
	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("NewApi")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if(convertView == null)
		{
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.message_list, null);
			viewHolder.listmessage = (TextView) convertView.findViewById(R.id.listmessage);
			convertView.setTag(viewHolder);			//表示给View添加一个格外的数据，


		} else {
			viewHolder = (ViewHolder)convertView.getTag();//通过getTag的方法将数据取出来
		}
		final String temp = viewHolder.listmessage.getText().toString();
		viewHolder.listmessage.setOnLongClickListener(new View.OnLongClickListener() {
			@Override
			public boolean onLongClick(View v) {
				TextView textView  =(TextView) v;
				ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
				cmb.setText(textView.getText().toString().trim()); //将内容放入粘贴管理器,在别的地方长按选择"粘贴"即可
				ToastUtils.showTextToast(context,"复制文本成功");
				return false;
			}
		});
		viewHolder.listmessage.setText(data.get(position));
		return convertView;
	}
	/**
	 * 定义一个内部类
	 * 声明相应的控件引用
	 *
	 */
	public class ViewHolder {
		public TextView listmessage;

	}
}